package javafx191labs.ssheypak.seminar01.gui;

import javafx.scene.CustomNode;

import javafx.scene.Node;
import javafx.scene.Group;
import javafx.ext.swing.SwingLabel;
import javafx.ext.swing.SwingComponent;
import javafx.ext.swing.SwingVerticalAlignment;

/**
 * Form for storing or updating persons.
 * @author ssheipak
 */

public class PersonForm extends CustomNode{

    /** Form title. */
    public var title: String;

    /** Form descr. hint. */
    public var description: String;

    /**Form rows with label titles and ui controls. */
    public var formRows : FormRow[];

    /** Returns input form ready for usage. */
    override protected function create () : Node {
       var labels:SwingLabel[];
       var uiControls: SwingComponent[];
       for (formRow in formRows){
            insert createLabel(formRow.title, formRow.uiControl) into labels;
            insert formRow.uiControl into uiControls;
       }

       return Group{
        content: [labels,uiControls]
       }
    }

    /** Creates SwingLabel. */
    public function createLabel(title:String, labelFor : SwingComponent) : SwingLabel {
        return SwingLabel{
                    text:title,
                    labelFor: labelFor,
                    verticalAlignment:SwingVerticalAlignment.TOP
               }
    }


}
